package com.atguigu.mapreduce.solution;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;

/**
 * 这是标准答案，请不要修改。如果实在没有思路，可以作为参考。
 */
public class SolutionDriver implements Tool {
    private Configuration conf;

    @Override
    public int run(String[] args) throws Exception {
        Job solution = Job.getInstance(conf);

        solution.setJobName("Order By Solution");

        solution.setMapperClass(SolutionMapper.class);
        solution.setReducerClass(SolutionReducer.class);
        solution.setCombinerClass(SolutionReducer.class);

        solution.setMapOutputKeyClass(OrderBean.class);
        solution.setMapOutputValueClass(NullWritable.class);
        solution.setCombinerKeyGroupingComparatorClass(UniGroupComparator.class);
        solution.setGroupingComparatorClass(UniGroupComparator.class);

        FileInputFormat.setInputPaths(solution, new Path("input"));
        FileOutputFormat.setOutputPath(solution, new Path("output/solution"));

        return solution.waitForCompletion(true) ? 0 : 1;
    }

    @Override
    public void setConf(Configuration configuration) {
        this.conf = configuration;
    }

    @Override
    public Configuration getConf() {
        return conf;
    }
}
